package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMeterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author ybw
 * @version 1.0
 * @date 2021/12/13 15:11
 */
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
  @Autowired private WmMaterialService wmMaterialService;
  /**
   * 上传素材
   *
   * @return
   */
  @PostMapping("/upload_picture")
  public ResponseResult uploadPicture(MultipartFile multipartFile) throws IOException {
    return wmMaterialService.uploadPicture(multipartFile);
  }

  /**
   * 素材列表
   *
   * @param wmMeterialDto
   * @return
   */
  @PostMapping("/list")
  public ResponseResult picList(@RequestBody WmMeterialDto wmMeterialDto) {
    return wmMaterialService.picList(wmMeterialDto);
  }

  /**
   * 删除图片
   *
   * @param id
   * @return
   */
  @GetMapping("/del_picture/{id}")
  public ResponseResult delPic(@PathVariable Integer id) {
    return wmMaterialService.delPic(id);
  }

  /**
   * 收藏图片
   *
   * @param id
   * @return
   */
  @GetMapping("/collect/{id}")
  public ResponseResult collect(@PathVariable Integer id) {
    return wmMaterialService.collect(id, 1);
  }

  /**
   * 取消收藏图片
   *
   * @param id
   * @return
   */
  @GetMapping("/cancel_collect/{id}")
  public ResponseResult cancelCollect(@PathVariable Integer id) {
    return wmMaterialService.collect(id, 0);
  }
}
